Make `action` a mandatory option in preparation for making it interpolated.

Akinori MUSHA 10 years ago
parent
commit
2d790b54ea

+ 1 - 1
app/concerns/agent_controller_concern.rb

@@ -12,7 +12,7 @@ module AgentControllerConcern
12 12
   end
13 13
 
14 14
   def control_action
15
-    options['action'].presence || 'run'
15
+    options['action']
16 16
   end
17 17
 
18 18
   def validate_control_action

+ 1 - 1
app/models/agents/scheduler_agent.rb

@@ -19,7 +19,7 @@ module Agents
19 19
 
20 20
       Set `action` to one of the action types below:
21 21
 
22
-      * `run`: This is the default.  Target Agents are run at intervals.
22
+      * `run`: Target Agents are run at intervals, except for those disabled.
23 23
 
24 24
       * `disable`: Target Agents are disabled (if not) at intervals.
25 25
 

+ 2 - 2
spec/lib/huginn_scheduler_spec.rb

@@ -86,11 +86,11 @@ describe Rufus::Scheduler do
86 86
 
87 87
     stub.any_instance_of(Agents::SchedulerAgent).second_precision_enabled { true }
88 88
 
89
-    @agent1 = Agents::SchedulerAgent.new(name: 'Scheduler 1', options: { schedule: '*/1 * * * * *' }).tap { |a|
89
+    @agent1 = Agents::SchedulerAgent.new(name: 'Scheduler 1', options: { action: 'run', schedule: '*/1 * * * * *' }).tap { |a|
90 90
       a.user = users(:bob)
91 91
       a.save!
92 92
     }
93
-    @agent2 = Agents::SchedulerAgent.new(name: 'Scheduler 2', options: { schedule: '*/1 * * * * *' }).tap { |a|
93
+    @agent2 = Agents::SchedulerAgent.new(name: 'Scheduler 2', options: { action: 'run', schedule: '*/1 * * * * *' }).tap { |a|
94 94
       a.user = users(:bob)
95 95
       a.save!
96 96
     }

+ 8 - 2
spec/models/agents/scheduler_agent_spec.rb

@@ -4,7 +4,10 @@ describe Agents::SchedulerAgent do
4 4
   let(:valid_params) {
5 5
     {
6 6
       name: 'Example',
7
-      options: { 'schedule' => '0 * * * *' },
7
+      options: {
8
+        'action' => 'run',
9
+        'schedule' => '0 * * * *'
10
+      },
8 11
     }
9 12
   }
10 13
 
@@ -73,7 +76,10 @@ describe Agents::SchedulerAgent do
73 76
 
74 77
       agent.memory['scheduled_at'] = time
75 78
       # Currently agent.options[]= is not detected
76
-      agent.options = { 'schedule' => '*/5 * * * *' }
79
+      agent.options = {
80
+        'action' => 'run',
81
+        'schedule' => '*/5 * * * *'
82
+      }
77 83
       agent.save
78 84
       expect(agent.memory['scheduled_at']).to be_nil
79 85
     end

+ 2 - 14
spec/support/shared_examples/agent_controller_concern.rb

@@ -10,12 +10,12 @@ shared_examples_for AgentControllerConcern do
10 10
 
11 11
   describe "validation" do
12 12
     it "should validate action" do
13
-      ['run', 'enable', 'disable', '', nil].each { |action|
13
+      ['run', 'enable', 'disable'].each { |action|
14 14
         agent.options['action'] = action
15 15
         expect(agent).to be_valid
16 16
       }
17 17
 
18
-      ['delete', 1, true].each { |action|
18
+      ['delete', '', nil, 1, true].each { |action|
19 19
         agent.options['action'] = action
20 20
         expect(agent).not_to be_valid
21 21
       }
@@ -23,18 +23,6 @@ shared_examples_for AgentControllerConcern do
23 23
   end
24 24
 
25 25
   describe 'control_action' do
26
-    it "should be one of the supported values" do
27
-      ['run', '', nil].each { |action|
28
-        agent.options['action'] = action
29
-        expect(agent.control_action).to eq('run')
30
-      }
31
-
32
-      ['enable', 'disable'].each { |action|
33
-        agent.options['action'] = action
34
-        expect(agent.control_action).to eq(action)
35
-      }
36
-    end
37
-
38 26
     it "cannot be 'run' if any of the control targets cannot be scheduled" do
39 27
       expect(agent.control_action).to eq('run')
40 28
       agent.control_targets = [agents(:bob_rain_notifier_agent)]